{% extends "base.html" %}
{% load navigation_tags %}
{% load authorization_tags %}
{% block content %}
    {{ block.super }}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading tight">
                    <h3 class="has-filters">
                        Environment List
                        <div class="dropdown pull-right">
                            <button id="show-filters" aria-label="Filters" data-toggle="collapse" data-target="#the-filters" class="btn btn-primary toggle-filters"> <i class="fa-solid fa-filter"></i> <i class="caret"></i> </button>
                            {% if "dojo.add_development_environment"|has_configuration_permission:request %}
                            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1"
                                    data-toggle="dropdown" aria-expanded="true" aria-label="Environment actions">
                                <span class="fa-solid fa-screwdriver-wrench"></span>
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu"
                                aria-labelledby="dropdownMenu1">
                                    <li role="presentation">
                                        <a href="{%  url 'add_dev_env' %}">
                                            <i class="fa-solid fa-plus"></i> New Environment </a>
                                    </li>
                            </ul>
                            {% endif %}
                        </div>
                    </h3>
                </div>
                <div id="the-filters" class="is-filters panel-body collapse {% if dts.form.has_changed %}in{% endif %}">
                    {% include "dojo/filter_snippet.html" with form=dts.form %}
                </div>
            </div>
            {% if devs %}
                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=devs page_size=True%}
                </div>
                <div class="panel panel-default table-responsive">
                    <table id="test_types"
                           class="tablesorter-bootstrap table table-bordered table-condensed table-striped">
                        <thead>
                        <tr>
                            {% comment %} The display field is translated in the function. No need to translate here as well{% endcomment %}
                            <th>{% dojo_sort request 'Environment' 'name' 'asc' %}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for de in devs %}
                            <tr>
                                {% if "dojo.change_development_environment"|has_configuration_permission:request %}
                                    <td><a href="{% url 'edit_dev_env' de.id %}"> {{ de.name }} </a></td>
                                {% else %}
                                    <td> {{ de.name }} </a> </td>
                                {% endif %}
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=devs page_size=True%}
                </div>
            {% else %}
                <p class="text-center">No environments found.</p>
            {% endif %}
        </div>

    </div>
{% endblock %}
{% block postscript %}
    {{ block.super }}
    <script>
        $(function () {
            var availableTags = [
                {% for word in name_words %}
                    "{{word}}",
                {% endfor %}
            ];
            $("#id_name").autocomplete({
                source: availableTags
            });
        });
    </script>
    {% include "dojo/filter_js_snippet.html" %}
{% endblock %}
